package cease.console;

/**
 * @author dhf
 */
public class TimeUtil {
    public static String compareNow(long time) {
        long timeInSec = time / 1000;
        long nowInSec = System.currentTimeMillis() / 1000;
        long interval = nowInSec - timeInSec;
        if (interval < 1) {
            return 1 + "秒前";
        } else if (interval < 60) {
            return interval + "秒前";
        } else if (interval < 60 * 60) {
            return interval / 60 + "分钟前";
        } else if (interval < 60 * 60 * 24) {
            return interval / 3600 + "小时前";
        } else if (interval < 60 * 60 * 24 * 30) {
            return interval / 86400 + "天前";
        } else if (interval < 60 * 60 * 24 * 365) {
            return interval / (86400 * 30) + "月前";
        } else {
            return interval / (86400 * 365) + "年前";
        }
    }
}
